import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  OneToOne,
  Relation,
  ManyToOne,
  JoinColumn,
} from 'typeorm'
import { UserGroup } from './UserGroup'
import { UserInfo } from './UserInfo'

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number

  @Column()
  name: string

  @Column({ select: false })
  password: string

  @Column()
  email: string

  @OneToOne((type) => UserInfo, (userInfo) => userInfo.user, {
    cascade: true,
  })
  userInfo: UserInfo

  @ManyToOne((type) => UserGroup, (userGroup) => userGroup.user, {
    cascade: true,
  })
  @JoinColumn()
  userGroup: UserGroup
}
